package com.chixing.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 数据源文件工具类
 * 获得dbconn.properties文件中的数据源信息
 */
public class DataSourceFileUtil {
    //1.获得数据源信息 该文件加载一次 static
    private static Properties properties ;
    static{
        properties = new Properties();
        InputStream is = DataSourceFileUtil.class.getResourceAsStream("/dbconn.properties");
        try {//加载数据源文件
            properties.load(is);
            System.out.println("加载数据源文件成功");
        }catch (Exception e) {
            e.printStackTrace();
        }finally {
            if(is != null)
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
        }
    }
    public static String getDriverName()
    {
        return properties.getProperty("driverName");
    }
    public static String getUrl()
    {
        return properties.getProperty("url");
    }
    public static String getUserName()
    {
        return properties.getProperty("userName");
    }
    public static String getPassword()
    {
        return properties.getProperty("password");
    }
    public static void main(String[] args) {
        String driverName = getDriverName();
        System.out.println(driverName);
    }
}
